package goodenglish.domain.service.impl;

import goodenglish.domain.model.lexicon.StudyInfo;
import goodenglish.domain.service.StudyWordSelect;
import goodenglish.infrastructure.Config;

import java.util.List;

public class StudyWordOrderSelect implements StudyWordSelect {
	@Override
	public StudyInfo next(List<StudyInfo> studyInfos, StudyInfo preNewWord) {
		StudyInfo currWord = null;
		if (preNewWord != null) {
			// 单词后面有没有没学过的
			boolean startFind = false;

			for (StudyInfo newWord : studyInfos) {
				if (startFind && newWord.getRightCount() < Config.RIGTH_COUNT) {
					currWord = newWord;
					break;
				}
				if (preNewWord.equals(newWord)) {
					startFind = true;
				}

			}
		}
		if (currWord == null) {
			// 如果单词后面没有，则从头找
			for (StudyInfo newWord : studyInfos) {
				if (newWord.getRightCount() < Config.RIGTH_COUNT) {
					currWord = newWord;
					break;
				}

			}
		}

		return currWord;
	}
}
